package fr.umlv.m2.jee.pmlv.service.user;

import javax.naming.NamingException;
import javax.naming.directory.Attributes;

import org.springframework.ldap.core.AttributesMapper;


/**
 * Class that Map LDAP information with class User.
 * 
 * @author Karim HAROUNI
 * 
 */
public class UserAttributeMapper implements AttributesMapper{

		/**
		 * methode that maps LDAP user in class User 
		 */
		public Object mapFromAttributes(Attributes attributes) throws NamingException {
			User user = new User();
			String commonName = (String)attributes.get("cn").get();
			if(commonName != null)
				user.setCommonName(commonName);
			String lastname = (String)attributes.get("sn").get();
			if(lastname != null)
			user.setLastname(lastname);
			String uId = (String)attributes.get("uId").get();
			if(uId != null)
				user.setuId(uId);
			String firstname = (String)attributes.get("givenName").get();
			if(firstname != null)
				user.setFirstname(firstname);
			String telephone = (String)attributes.get("telephoneNumber").get();
			if(telephone != null)
				user.setTelephone(telephone);
			String mobile = (String)attributes.get("mobile").get();
			if(mobile != null)
				user.setMobile(mobile);
			String number = (String)attributes.get("employeeNumber").get();
			if(number != null)
				user.setNumber(number);
			String mail = (String)attributes.get("mail").get();
			if(mail != null)
				user.setMail(mail);
			String postalAddress = (String)attributes.get("postalAddress").get();
			if(postalAddress != null)
				user.setPostalAddress(postalAddress);

			return user;
		}

}
